{/*

    ==账户/其他相关操作==

*/}
<style>
    .el-dropdown-link {
        cursor: pointer;
        align-items: center;
        line-height: 50px;
        outline: none;
    }

    .vue--account{
        margin: 0 10px;
    }
</style>

<script type="text/html" id="account-info">
    <el-dialog destroy-on-close title="创建基础CURD" v-model="curdDialog" width="1450" align-center ref="curd">
        <i-frame :url="curdUrl" style="width: 1400px"></i-frame>
    </el-dialog>
    <el-dialog destroy-on-close title="更新CURD" v-model="updateCurdDialog" width="1450" align-center ref="curd">
        <i-frame :url="updateCurdUrl" style="width: 1400px"></i-frame>
    </el-dialog>
    <el-dialog destroy-on-close title="数据备份" v-model="backupDialog" width="1550" align-center ref="backup">
        <i-frame :url="dataBackUpUrl" style="width: 1500px"></i-frame>
    </el-dialog>
    <el-dialog @close="closeUpdatePassword" title="修改密码" v-model="updatePassword" width="500" align-center ref="updatePassword">
        <el-form ref="updatePasswordForm" label-width="100px">
            <el-form-item label="旧密码">
                <el-input v-model="updPwd.old" type="password" show-password></el-input>
            </el-form-item>
            <el-form-item label="新密码">
                <el-input v-model="updPwd.new" type="password" show-password></el-input>
            </el-form-item>
            <el-form-item label="确认密码">
                <el-input v-model="updPwd.new_confirm" type="password" show-password></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
          <span class="dialog-footer">
            <el-button @click="updatePassword = false">取消</el-button>
            <el-button type="primary" @click="updatePasswordHandle">
              确认修改
            </el-button>
          </span>
        </template>
    </el-dialog>
    <?php if(\App\Common\Util\AdminAuth::isSuper() && class_exists('\\Plugins\\Dev\\Admin\\Controller\\DevAuxController')) { ?>
    <el-dropdown class="vue--account" v-if="dev">
        <span class="el-dropdown-link">
            开发工具
        </span>
        <template #dropdown>
            <el-dropdown-menu>
                <el-dropdown-item @click="curd('<?= tp()->toAllowMiss([\Plugins\Dev\Admin\Controller\DevAuxController::class, 'baseFileMake']) ?>')">创建基础CURD</el-dropdown-item>
                <el-dropdown-item @click="updateCurd('<?= tp()->toAllowMiss([\Plugins\Dev\Admin\Controller\DevAuxController::class, 'baseFileUpdate']) ?>')">更新Model</el-dropdown-item>
            </el-dropdown-menu>
        </template>
    </el-dropdown>
    <?php } ?>
    <?php if(\App\Common\Util\AdminAuth::isSuper()) { ?>
    <span @click="dataBackUp" class="vue--account el-dropdown-link"  style="display: inline-block;font-size: 14px;color: var(--el-text-color-regular)">
        <el-icon style="top: 2px; right: 2px"><Coin /></el-icon>数据备份
    </span>
    <?php } ?>
    <el-dropdown class="vue--account" >
        <span class="el-dropdown-link">
            <el-icon style="top: 2px; right: 2px"><UserFilled/></el-icon>
            <?= \App\Common\Util\AdminAuth::getInfo()->name ?>
            <el-icon style="top: 2px; "><ArrowDownBold/></el-icon>
        </span>
        <template #dropdown>
            <el-dropdown-menu>
                <el-dropdown-item @click="updatePassword = true">修改密码</el-dropdown-item>
                <el-dropdown-item @click="loginOut">退出登录</el-dropdown-item>
            </el-dropdown-menu>
        </template>
    </el-dropdown>
</script>

<script>

    VueInit.components.AccountInfo = {
        template: document.getElementById('account-info').innerHTML,
        data() {
            return {
                dev: ENV.IS_DEV,
                updatePassword: false,
                updatePasswordUrl: "<?= \App\Common\Util\TP::route()->to([\App\Admin\Controller\Base\UpdatePasswordController::class, 'updatePassword']) ?>",
                updPwd:{
                    old:'',
                    new:'',
                    new_confirm:'',
                },
                curdDialog:false,
                curdUrl: '',
                updateCurdDialog:false,
                updateCurdUrl: '',
                backupDialog:false,
                dataBackUpUrl:'',
                dataBackUpUrlInit:'<?= \App\Common\Util\TP::route()->to([\App\Admin\Controller\Base\DataBackUpController::class, 'backup']) ?>',
                loginOutUrl:"<?= \App\Common\Util\TP::route()->to([\App\Admin\Controller\Base\LoginController::class, 'loginOut']) ?>"
            }
        },
        methods: {
            curd:function (url){
                this.curdUrl = url;
                this.curdDialog = true;
            },
            updateCurd:function (url){
                this.updateCurdUrl = url;
                this.updateCurdDialog = true;
            },
            dataBackUp:function (){
                this.dataBackUpUrl = this.dataBackUpUrlInit;
                this.backupDialog = true;
            },
            loginOut(){
                top.location.href = this.loginOutUrl;
            },
            closeUpdatePassword(){
                this.updPwd = {
                    old: '',
                    new: '',
                    new_confirm: '',
                };
            },
            updatePasswordHandle(){
                axios({
                    url: this.updatePasswordUrl,
                    data: this.updPwd,
                    method: 'post'
                }).then(({ data }) => {
                    if(data.code === 200){
                        this.updatePassword = false;
                        this.$message.success("修改成功，下次登陆请使用新密码登录")
                    }else{
                        this.$message.error(data.msg)
                    }
                }).catch(() =>{
                    this.$message.error("服务器错误")
                });
            }
        }
    }
</script>